﻿using System;
using System.Collections.Generic;
using System.Text;
using KKCai.SC.App.Model;

namespace KKCai.SC.App.DAL
{
    public class DayCountDao : Core.AbstractDao<DayCountInfo>
    {
        private const string hql = "select c.Value from DayCountInfo c";

        public IList<int> List()
        {
            return Session.CreateQuery(hql).List<int>();
        }

        public int Update(string result)
        {
            string[] array = result.Split(',');
            array[1] = (Convert.ToInt32(array[1]) + 12).ToString();
            array[2] = (Convert.ToInt32(array[2]) + 24).ToString();

            result = String.Format("{0},{1},{2}", array[0], array[1], array[2]);
            
            string hql = String.Format("update DayCount set Value = Value + 1 where ID in ( {0} )", result);

            return Session.CreateSQLQuery(hql).ExecuteUpdate();
        }

        public int Reset()
        {
            string hql = "update DayCount set Value = 0";

            return Session.CreateSQLQuery(hql).ExecuteUpdate();
        }
    }
}
